package com.itheima.tezheng;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/*
原子性问题


 */
public class Demo03 {

    public static void main(String[] args) throws InterruptedException {
        Suibian suibian = new Suibian();
        Thread t1 = new Thread(suibian);
        Thread t2 = new Thread(suibian);
        Thread t3 = new Thread(suibian);
        Thread t4 = new Thread(suibian);
        Thread t5 = new Thread(suibian);

        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();


        Thread.sleep(3000);

        System.out.println(suibian.number);

    }
}


class Suibian implements Runnable {
    volatile AtomicInteger number = new AtomicInteger(0);
    Object obj = new Object();
    Lock lock = new ReentrantLock();

    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
///lock.lock();
            //  synchronized (obj){
            //number++;
            number.incrementAndGet();
            //     }

            // lock.unlock();
        }
    }
}